﻿/*******************************************************************************
 * Copyright © 2017 FriendStar.Framework 版权所有
 * Author: FZH
 * Description: FriendStar快速开发平台
 * Website：http://www.FriendStar.cn
*********************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using SqlSugarRepository;
using FriendStar.Code;
using FriendStar.Domain.Entity.BOM;
using FriendStar.Domain.IRepository.BOM;
using FriendStar.Repository.BOM;

namespace FriendStar.Application.BOM
{
    /// <summary>
	/// 数据表 ZSJ_21_RQ_DatContainer 对应的数据应用功能类。
	/// </summary>
	public class ZSJ_21_RQ_DatContainerApp
    {       
        private string UseUnit = Configs.GetValue("UseUnit");  

        private IZSJ_21_RQ_DatContainerRepository service = new ZSJ_21_RQ_DatContainerRepository();

        public List<ZSJ_21_RQ_DatContainerEntity> GetList(Pagination pagination, string keyword)
        {
            var expression = ExtLinq.True<ZSJ_21_RQ_DatContainerEntity>();

            if (!string.IsNullOrEmpty(keyword))
            {
                expression = expression.And(t => t.FContainerID == keyword);
            }
            return service.FindList(expression, pagination);
        }

        public List<ZSJ_21_RQ_DatContainerEntity> GetList()
        {
            var expression = ExtLinq.True<ZSJ_21_RQ_DatContainerEntity>();
            expression = expression.And(t => t.UseUnit == UseUnit);
            Pagination pagination = new Pagination();
            pagination.rows = int.MaxValue;
            pagination.sidx = "FContainerNO";
            pagination.sord = "asc";
            return service.FindList(expression, pagination);
        }

        public ZSJ_21_RQ_DatContainerEntity GetForm(string keyValue)
        {
            return service.FindEntity(keyValue);
        }

        public void DeleteForm(string keyValue)
        {
            service.Delete(t => t.FContainerID == keyValue);
        }

        public void SubmitForm(ZSJ_21_RQ_DatContainerEntity entity, string keyValue)
        {
            if (!string.IsNullOrEmpty(keyValue))
            {
                service.Update(entity);
            }
            else
            {
                entity.FContainerID = Common.GuId();
                entity.UseUnit = UseUnit;
                service.Insert(entity);
            }
        }
    }
}